package com.lbb.utils.recycler

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

class LinearSpacingItemDecoration(private val spacing: Int, private val includeEdge: Boolean) : RecyclerView.ItemDecoration() {


    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
       // super.getItemOffsets(outRect, view, parent, state)
        val position = parent.getChildAdapterPosition(view)
        val size = parent.adapter?.itemCount
        size?.let {
            if (includeEdge){
                outRect.top = spacing
                if(position==size-1){
                    outRect.bottom = spacing
                }
            }else{
                if(position!=size-1){
                    outRect.bottom = spacing
                }
            }
        }

    }
}